<?php
include 'inc/functions.php';
connectToDatabase();

//====== variables ================================================
$companyName = sanitizeStr($_POST['Company']);
$address1 = sanitizeStr($_POST['Address']);
$address2 = sanitizeStr($_POST['Address2']);
$city = sanitizeStr($_POST['City']);
$state = sanitizeStr($_POST['State']);
$zip = sanitizeStr($_POST['Zip']);
$description = sanitizeStr($_POST['OrgDesc']);
$firstName = sanitizeStr($_POST['FirstName']);
$lastName = sanitizeStr($_POST['LastName']);
$email = sanitizeStr($_POST['Email']);
$phone = sanitizeStr($_POST['Phone']);
$ext = sanitizeStr($_POST['Ext']);
$fax = sanitizeStr($_POST['Fax']);
$positionTitle = sanitizeStr($_POST['PositionTitle']);
$numberPositions = sanitizeStr($_POST['PositionNumber']);
$availability = sanitizeStr($_POST['Availability']);
$payrate = sanitizeStr($_POST['PayRate']);
if ($payrate == 'Paid') {
	$payrate = '1.00';
} else {
	$payrate = '0.00';
}
$duration = sanitizeStr($_POST['PositionDuration']);
$responsibilities = sanitizeStr($_POST['Responsibilities']);
$qualifications = sanitizeStr($_POST['Qualifications']);
$instructions = sanitizeStr($_POST['Instructions']);
$comments = sanitizeStr($_POST['Comments']);
//========================================================================


if (isset($_POST['orgDropDown'])) {
	$orgName = $_POST['orgDropDown'];
	if ($orgName == '') {
		//no company selected
	} else {
		$result = mysql_query("SELECT * FROM organization WHERE name='$orgName'");
		if (!$result

		)die("Could not the query! Please contact the MySQL database admin.");
		$row = mysql_fetch_assoc($result);
		$companyName = restoreStr($row[name]);
		$description = restoreStr($row[companyDescription]);
		$address1 = restoreStr($row[address]);
		$address2 = restoreStr($row[address1]);
		$city = restoreStr($row[city]);
		$state = restoreStr($row[state]);
		$zip = restoreStr($row[zip]);
	}
}

if (isset($_POST['submitButton'])) {
	//form has been submitted.
	$error += checkAgreements();
	$error += checkRequired();
	if ($error > 0) {
		//do nothing, missing information
	} else {
		connectToDatabase();
		submitInformation($companyName, $address1, $address2, $city, $state, $zip, $description, $firstName, $lastName, $email, $phone, $ext, $fax, $positionTitle, $numberPositions, $availability, $payrate, $duration, $responsibilities, $qualifications, $instructions, $comments);
		displaySuccessForm();
		clearInfo($companyName, $address1, $address2, $city, $state, $zip, $description, $firstName, $lastName, $email, $phone, $ext, $fax, $positionTitle, $numberPositions, $availability, $payrate, $duration, $responsibilities, $qualifications, $instructions, $comments);
	}
}

function clearInfo(&$companyName, &$address1, &$address2, &$city, &$state, &$zip, &$description, &$firstName, &$lastName, &$email, &$phone, &$ext, &$fax, &$positionTitle, &$numberPositions, &$availability, &$payrate, &$duration, &$responsibilities, &$qualifications, &$instructions, &$comments) {
	$companyName = '';
	$address1 = '';
	$address2 = '';
	$city = '';
	$state = '';
	$zip = '';
	$description = '';
	$firstName = '';
	$lastName = '';
	$email = '';
	$phone = '';
	$ext = '';
	$fax = '';
	$positionTitle = '';
	$numberPositions = '';
	$availability = '';
	$payrate = '';
	$duration = '';
	$responsibilities = '';
	$qualifications = '';
	$instructions = '';
	$comments = '';
}

function displaySuccessForm() {
	echo "<script language='javascript'>alert('Your information has been submitted! Thank you!')</script>";
	echo "<a href='http://www.unhm.unh.edu/current-students/academics/internships/'>Back to UNHM Internships</a>";
}

function submitInformation(&$companyName, &$address1, &$address2, &$city, &$state, &$zip, &$description, &$firstName, &$lastName, &$email, &$phone, &$ext, &$fax, &$positionTitle, &$numberPositions, &$availability, &$payrate, &$duration, &$responsibilities, &$qualifications, &$instructions, &$comments) {

	$orgExists = chkCompAlreadyExists($companyName);

	if (!$orgExists) { //org does not exist
		mysql_query("INSERT INTO ORGANIZATION VALUES('', '$companyName', '$description', '$address1', '$address2','$city','$state','$zip')") or die(mysql_error());
		$result = mysql_query("SELECT organizationID FROM ORGANIZATION WHERE name='$companyName'");
		$row = mysql_fetch_row($result);
		$id = $row[0];
	} else {
		$result = mysql_query("SELECT organizationID FROM ORGANIZATION WHERE name='$companyName'");
		$row = mysql_fetch_row($result);
		$id = $row[0];
	}

	mysql_query("INSERT INTO CONTACTS VALUES('','$id','$firstName','$lastName','$email','$phone','$ext','$fax')") or die(mysql_error());
	//get contact ID
	$result = mysql_query("SELECT contactID FROM contacts WHERE contactFirst='$firstName' AND contactLast='$lastName'");
	$row = mysql_fetch_assoc($result);
	$contactID = $row[contactID];
	mysql_query("INSERT INTO INTERNSHIP_OPPORTUNITY VALUES('','$id','$contactID','$positionTitle','$numberPositions','$availability','$payrate','$duration','$responsibilities','$qualifications','$instructions','$comments','',curdate())") or die(mysql_error());
}

function chkCompAlreadyExists($orgName) {
	$result = mysql_query("SELECT * FROM organization WHERE name='$orgName'");
	if (!$result

	)die("Query failed.");
	$num = mysql_num_rows($result);
	if ($num == 0) {
		//no results, company does not exist
		return 0;
	} else {
		return 1;
	}
}

function companyDropDown() {

	$result = mysql_query("SELECT DISTINCT name FROM organization");
	if (!$result

	)die("Could not complete the query...");
	$numRows = mysql_num_rows($result);
	echo '<form action="internship-request.php" method="POST">';
	echo "<div align='left'>";
	echo "<select onchange='this.form.submit()' name='orgDropDown'><br />";
	echo "</div>";
	echo "<option value=''></option>";
	for ($i = 0; $i < $numRows; $i++) {
		$row = mysql_fetch_assoc($result);
		if (strcmp($row[name], $orgName) == 0) {
			echo "<option SELECTED value='$row[name]'>$row[name]</option>";
		} else {
			echo "<option value='$row[name]'>$row[name]</option>";
		}
	}
	echo "</select>";
	echo "</form>";
}

/*
 * Check required
 */

function checkRequired() {
	/* if($_POST['Company'] == '' || $_POST['Address']=='' || $_POST['City']=='' || $_POST['State']=='' || $_POST['Zip']=='' || $_POST['FirstName']=='' || $_POST['LastName']=='' || $_POST['Email']=='' || $_POST['Phone']=='' || $_POST['PositionTitle']=='' || $_POST['PositionNumber']=='' || $_POST['Availability']==''  || $_POST['PayRate']=='' || $_POST['PositionDuration']=='' || $_POST['Responsibilities']=='' || $_POST['Qualifications']=='')
	 {
	 echo "<script language='javascript'>alert('You must fill out all required information. Marked by a *.')</script>";
	 return 1;
	 } */
}

/*
 * Check agreements
 */

function checkAgreements() {
	$uacc = $_POST['UACC'];
	$diversity = $_POST['unhdiversity'];
	$deptlabor = $_POST['deptlabor'];

	if ($uacc == 'yes' && $diversity == 'yes' && $deptlabor == 'yes') {
		//everything has been submitted
		return 0;
	} else {//something is missing
		echo "<script language='javascript'>alert('You must accept all the terms in order to submit your request.')</script>";
		return 1;
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//Dtd XHTML 1.0 transitional//EN" "http://www.w3.org/tr/xhtml1/Dtd/xhtml1-transitional.dtd">

<html xml:lang="en" lang="en">

<head>

<title>Internship Request Form</title>

<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />

<meta name="language" content="English" />

<link rel="stylesheet" type="text/css" href="css/style.css" />

</head>


<body>


<h1>Request Information</h1>

<form action="internship-request.php" method="POST"><!--<input type="hidden" value="1" name="submitForm" />-->

<font color='red'>* = Required</font>

<div align="center">
<table width="600" border="1">
	<tr>
		<td bgcolor="white">

		<table BORDER="0" CELLPADDING="2" CELLSPACING="0" width="100%">

			<tr>

				<td>
				<p><strong>Company Information:</strong>
				
				</td>

				<td></td>

			</tr>

			<tr>

				<td width="200"><font color='red'>*</font> Company Name:</td>

				<td><?php
				if ($companyName == '') {
					echo "<INPUT TYPE='text' NAME='Company' VALUE='$companyName' size='25' maxlength='50' />";
				} else {
					echo "<INPUT TYPE='text' NAME='Company' readonly='readonly' VALUE='$companyName' size='25' maxlength='50' />";
				}
				?></td>

			</tr>

			<tr>

				<td width="200">Existing Company:</td>

				<td><?php companyDropDown(); ?></td>

			</tr>

			<tr>

				<td><font color='red'>*</font> Address:</td>

				<td><?php
				if ($address1 == '') {
					echo "<INPUT TYPE='text' NAME='Address' VALUE='$address1' size='25' maxlength='50' />";
				} else {
					echo "<INPUT TYPE='text' NAME='Address' readonly='readonly' VALUE='$address1' size='25' maxlength='50' />";
				}
				?></td>

			</tr>

			<tr>

				<td></td>

				<td><?php
				if ($address2 == '') {
					echo "<INPUT TYPE='text' NAME='' VALUE='$address2' size='25' maxlength='50' />";
				} else {
					echo "<INPUT TYPE='text' NAME='' readonly='readonly' VALUE='$address2' size='25' maxlength='50' />";
				}
				?></td>

			</tr>

			<tr>

				<td><font color='red'>*</font> City:</td>

				<td><?php
				if ($city == '') {
					echo "<INPUT TYPE='text' NAME='City' VALUE='$city' size='25' maxlength='50' />";
				} else {
					echo "<INPUT TYPE='text' NAME='City' readonly='readonly' VALUE='$city' size='25' maxlength='50' />";
				}
				?></td>

			</tr>

			<tr>

				<td><font color='red'>*</font> State:</td>

				<td><SELECT NAME="State" class="select">
				<?php
				if ($state == 'MA') {
					echo "<option value='MA' SELECTED>MA</option><option value='ME'>ME</option><option value='NH' >NH</option><option value='VT'>VT</option>";
				} else if ($state == 'NH') {
					echo "<option value='MA' >MA</option><option value='ME'>ME</option><option value='NH' SELECTED>NH</option><option value='VT'>VT</option>";
				} else if ($state == 'ME') {
					echo "<option value='MA' >MA</option><option value='ME' SELECTED>ME</option><option value='NH' >NH</option><option value='VT'>VT</option>";
				} else if ($state == 'VT') {
					echo "<option value='MA' >MA</option><option value='ME'>ME</option><option value='NH' >NH</option><option value='VT'SELECTED>VT</option>";
				} else {
					echo "<option value='MA' >MA</option><option value='ME'>ME</option><option value='NH' SELECTED>NH</option><option value='VT'>VT</option>";
				}
				?>
				</SELECT></td>
			</tr>

			<tr>

				<td><font color='red'>*</font> Zip Code:</td>

				<td><?php
				if ($zip == '') {
					echo "<INPUT TYPE='text' NAME='Zip' VALUE='$zip' size='25' maxlength='50' />";
				} else {
					echo "<INPUT TYPE='text' NAME='Zip' readonly='readonly' VALUE='$zip' size='25' maxlength='50' />";
				}
				?></td>

			</tr>

			<tr>

				<td valign="top">
				<p>Organization Description:
				
				</td>

				<td><?php
				if ($description == '') {
					echo "<textarea NAME='OrgDesc' class='textarea'>$description</textarea>";
				} else {
					echo "<textarea NAME='OrgDesc' readonly='readonly' class='textarea'>$description</textarea>";
				}
				?></td>

			</tr>

			<tr>

				<td>
				<p><strong>Contact Information:</strong>
				
				</td>

				<td></td>

			</tr>

			<tr>

				<td><font color='red'>*</font> First Name:</td>

				<td><INPUT TYPE="text" NAME="FirstName" SIZE="25"
					VALUE='<?php echo $firstName; ?>' maxlength="50" /></td>

			</tr>

			<tr>

				<td><font color='red'>*</font> Last Name:</td>

				<td><INPUT TYPE="text" NAME="LastName" SIZE="25"
					VALUE='<?php echo $lastName; ?>' maxlength="50" /></td>

			</tr>

			<tr>

				<td><font color='red'>*</font> Email Address:</td>

				<td><INPUT TYPE="text" NAME="Email" SIZE="25"
					VALUE="<?php echo $email; ?>" maxlength="50" /></td>

			</tr>

			<tr>

				<td><font color='red'>*</font> Phone Number:</td>

				<td><INPUT TYPE="text" NAME="Phone" SIZE="25"
					VALUE="<?php echo $phone; ?>" maxlength="50" /></td>

			</tr>

			<tr>

				<td>
				<p>Extension:
				
				</td>

				<td><INPUT TYPE="text" NAME="Ext" SIZE="25"
					VALUE="<?php echo $ext; ?>" maxlength="10" style="width: 50px;" /></td>

			</tr>

			<tr>

				<td>
				<p>Fax Number:
				
				</td>

				<td><INPUT TYPE="text" NAME="Fax" SIZE="25"
					VALUE="<?php echo $fax; ?>" maxlength="50" /></td>

			</tr>

			<tr>

				<td>
				<p><strong>Intern Position Information:</strong>
				
				</td>

				<td></td>

			</tr>

			<tr>

				<td><font color='red'>*</font> Position Title:</td>

				<td><INPUT TYPE="text" NAME="PositionTitle"
					VALUE="<?php echo $positionTitle; ?>" maxlength="100" /></td>

			</tr>

			<tr>

				<td><font color='red'>*</font> Number of Positions:</td>

				<td><INPUT TYPE="text" NAME="PositionNumber"
					VALUE="<?php echo $numberPositions; ?>" maxlength="25" /></td>

			</tr>

			<tr>

				<td><font color='red'>*</font> Availability:</td>

				<td><select name="Availability">

					<option value="">Select a value</option>
					<?php
					if ($_POST['Availability'] == '2010 Fall') {
						echo"<option value='2010 Fall' SELECTED>Fall (September - December)</option><option value='2010 Spring' >Spring (January - May)</option><option value='2010 Summer' >Summer (May - August)</option><option value='On-Going' >On-Going</option>";
					} else if ($_POST['Availability'] == '2010 Spring') {
						echo"<option value='2010 Fall' >Fall (September - December)</option><option value='2010 Spring' SELECTED>Spring (January - May)</option><option value='2010 Summer' >Summer (May - August)</option><option value='On-Going' >On-Going</option>";
					} else if ($_POST['Availability'] == '2010 Summer') {
						echo"<option value='2010 Fall' >Fall (September - December)</option><option value='2010 Spring' >Spring (January - May)</option><option value='2010 Summer' SELECTED>Summer (May - August)</option><option value='On-Going' >On-Going</option>";
					} else if ($_POST['Availability'] == 'On-Going') {
						echo"<option value='2010 Fall' >Fall (September - December)</option><option value='2010 Spring' >Spring (January - May)</option><option value='2010 Summer' >Summer (May - August)</option><option value='On-Going' SELECTED>On-Going</option>";
					} else {
						echo"<option value='2010 Fall' >Fall (September - December)</option><option value='2010 Spring' >Spring (January - May)</option><option value='2010 Summer' >Summer (May - August)</option><option value='On-Going' >On-Going</option>";
					}
					?>
				</select></td>

			</tr>

			<tr>

				<td><font color='red'>*</font> Pay Rate:</td>

				<td><select name="PayRate">
				<?php
				if ($_POST['PayRate'] == 'Paid') {
					echo "<option value=''>Select a value</option><option value='Paid' SELECTED>Paid</option><option value='Unpaid' >Unpaid</option>";
				} else if ($_POST['PayRate'] == 'Paid') {
					echo "<option value=''>Select a value</option><option value='Paid' >Paid</option><option value='Unpaid' SELECTED>Unpaid</option>";
				} else {
					echo "<option value=''>Select a value</option><option value='Paid' >Paid</option><option value='Unpaid' >Unpaid</option>";
				}
				?>
				</select></td>

			</tr>

			<tr>

				<td><font color='red'>*</font> Duration of Position:</td>

				<td><INPUT TYPE="text" NAME="PositionDuration"
					VALUE="<?php echo $duration; ?>" maxlength="150" /></td>

			</tr>

			<tr>

				<td valign="top"><font color='red'>*</font>Responsibilities:</td>

				<td><textarea cols="30" rows="5" name="Responsibilities"
					class="textarea"><?php echo $responsibilities; ?></textarea></td>

			</tr>

			<tr>

				<td valign="top"><font color='red'>*</font>Qualifications:</td>

				<td><textarea cols="30" rows="5" name="Qualifications"
					class="textarea"><?php echo $qualifications; ?></textarea></td>

			</tr>

			<tr>

				<td valign="top">
				<p>Instructions for Application:
				
				</td>

				<td><textarea cols="30" rows="5" name="Instructions"
					class="textarea"><?php echo $instructions; ?></textarea></td>

			</tr>

			<tr>

				<td valign="top">
				<p>Questions or Comments:
				
				</td>

				<td><textarea cols="30" rows="5" name="Comments" class="textarea"><?php echo $comments; ?></textarea></td>

			</tr>





			<tr>

				<td>&nbsp;</td>

				<td colspan="2">&nbsp;</td>

			</tr>

			<tr>

				<td colspan="2">
				<p><strong>UNH&#8217;S COMMITMENT TO DIVERSITY</strong>:<br />
				The University of New Hampshire recognizes that, to be successful in
				an increasingly global and interconnected world, our students need
				the skills to work effectively with those different from themselves.
				We ask that our student respect those different from them and make
				the same request of those who participate in our programs. UNH is a
				public institution with a long-standing commitment to equal
				opportunity for all. To insure that opportunity for all, the

				University does not discriminate on the basis of race, color,
				religion, sex, age, national origin, sexual orientation, gender

				identity or expression, disability, veteran status, or marital
				status, in admission or access to, or treatment or employment in,
				its programs, activities or services. Visit www.unh.edu/diversity
				for more information about UNH&#8217;s Commitment to Diversity. </font>
				
				
				<div align="left"><strong>I'VE READ THE UNH COMMITMENT TO DIVERSITY
				STATEMENT: </strong> <strong><font color="#993333">*</font></strong>

				<input class="checkbox" name="unhdiversity" type="checkbox"
					id="unhdiversity" value="yes"></div>

				<table width="103" border="0" align="center">

					<tr>



					</tr>

				</table>



				</td>

			</tr>

			<tr>

				<td colspan="3">&nbsp;</td>

			</tr>

			<tr>

				<td colspan="3">
				<p><strong>UNH MANCHESTER REPORTING:</strong></font>
				
				
				<p>The Internship Office periodically surveys employers to assess
				the quality of our interns and their experience so that we may
				improve the internship experience for our students and organizations
				offering internships. Thank you in advance for responding to our
				inquiries.<br>

				<strong><font color="#993333">*</font></strong> <input
					class="checkbox" name="UACC" type="checkbox" id="UACC" value="yes">

				I agree that my organization will provide UNH Manchester Internship
				Program with the names, job titles and duration of any UNH
				Manchester students who intern with us upon request.
				
				</td>

			</tr>



			<tr>

				<td colspan="3">&nbsp;</td>

			</tr>

			<tr>

				<td colspan="3">
				<p><strong>NH DEPARTMENT OF LABOR REPORTING:</strong></font>
				
				
				<p><strong><font color="#993333">*</strong> <input class="checkbox"
					name="deptlabor" type="checkbox" id="deptlabor" value="yes"> By

				posting this internship, I agree to comply with all NH Dept. of
				Labor reporting requirements and will complete the appropriate forms
				where applicable to our organization&rsquo;s internship
				opportunities.
				
				</td>

			</tr>



			<tr>

				<td colspan="2" align="center"><input name="submitButton"
					type="submit" class="submitContact" value="Submit" /></td>

			</tr>

		</table>

		</td>
	</tr>
</table>
</div>

<tr>

	<td>&nbsp;</td>

	<td colspan="2">&nbsp;</td>

</tr>



<br />

<p>Supplemental information may be submitted via email as a WORD
attachment, and/or embedded in the body of the e-mail. Please e-mail
information to <!-- This script can be used FREELY as long as this copyright message is intact: Mail Spam Blocker / Copyright (c) 2004 by www.myvasco.com Internet Marketing Solutions -->

<a
	href="&#109;&#x61;&#x69;&#x6c;&#x74;&#x6f;&#x3a;&#100;&#x6f;nn&#x61;&#46;mc&#105;n&#x74;&#105;&#x72;e&#64;u&#x6e;&#104;&#x2e;&#x65;&#x64;u">d&#111;&#110;&#x6e;&#97;.&#x6d;&#99;&#x69;&#110;t&#x69;r&#x65;&#64;&#117;&#x6e;&#104;&#x2e;&#101;&#x64;&#117;</a>.</font>


<p>Your request will be reviewed and you will receive a response within
5 business days.</font>

</form>





<div id="Honeypot">This field is used to deter BOTs from spamming us. If
you see this field, please leave it blank. <input type="text"
	name="Honeypot" value="" /></div>


<!-- end mainContent -->


</body>

</html>
